﻿/*
* Copyright (c) 2011, Johnson County Community College (JCCC)
* All rights reserved.
* BSD License: http://www.opensource.org/licenses/bsd-license.php
* 
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
*    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
*      in the documentation and/or other materials provided with the distribution.
*    * Neither the name of JCCC nor the names of its contributors may be used to endorse or promote products derived 
*      from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
using System.Collections.Generic;
using UnityEngine;


public struct Rectangle
{
    public int Width;
    public int Height;
    public int X;
    public int Y;

    public int Right { get { return X + Width; } }
    public int Left { get { return X; } }
    public int Top { get { return Y; } }
    public int Bottom { get { return Y + Height; } }

    public bool Intersects(Rectangle other)
    {
        int iLeft = (int)Mathf.Max(this.X, other.X);
        int iRight = (int)Mathf.Min(this.Right, other.Right);
        int iTop = (int)Mathf.Max(this.Y, other.Y);
        int iBottom = (int)Mathf.Min(this.Bottom, other.Bottom);

        return (iRight > iLeft && iBottom > iTop);
    }
}

    public class Dungeon
    {
        public int[] tileMap;
        //public List<XnaUtility.GameObjects.Base2DObject> objects;
        public List<DungeonRoom> rooms;
        public List<Corridor> corridors;
        public IDungeonMapGenerator generator;
        public int dungeonWidth;
        public int dungeonHeight;
        //public Utility.Logging.Logger log;
        //public Game game;

        //public Dungeon(Game game)
        public Dungeon()
        {
            rooms = new List<DungeonRoom>();
            //objects = new List<GameObjects.Base2DObject>();
            corridors = new List<Corridor>();
            tileMap = new int[1];
            //this.game = game;

            //EqatecMonitor.SendFeature("Rogue.Dungeon");
        }

        public void SetDungeonsize(int width, int height)
        {
            this.dungeonHeight = height;
            this.dungeonWidth = width;
            tileMap = new int[width * height];
            for (int i = 0; i < tileMap.Length; i++) tileMap[i] = 0;
        }

        public void NewDungeon()
        {
            rooms.Clear();
            corridors.Clear();
            //objects.Clear();
            for (int i = 0; i < tileMap.Length; i++) tileMap[i] = 0;
            generator.GenerateMap(this);
        }
    }
